package de.tabuma.lib.contentmanagement;

import de.tabuma.lib.contentmanagement.entity.*;
import javax.servlet.http.*;
import java.util.*;
import java.util.logging.*;
import com.google.appengine.api.users.*;

/**
 *
 * @author alefen
 */
public class ViewFacade {

    private static final Logger log = Logger.getLogger(ViewFacade.class.getName());

    public static String view(Content content, HttpServletRequest request) {
        if(content==null) {
            return "";
        }
        String str = "";
        Integer nav = (Integer) request.getAttribute(content.GeneralContent.getParamName());
        if(nav==null) {
            nav = constants.LIST;
        }
        
        try {
            switch(nav) {
                case constants.CREATE:
                    str += de.tabuma.lib.cm.crud.CreateViewFacade.view(content, request);
                    break;

                case constants.UPDATE:
                    str += de.tabuma.lib.cm.crud.UpdateViewFacade.view(content, request);
                    break;

                case constants.REMOVE:
                    str += de.tabuma.lib.cm.crud.RemoveViewFacade.view(content, request);
                    break;

                default:
                    str += de.tabuma.lib.cm.crud.ListViewFacade.view(content, request);
                    break;
            }
        }
        catch(Exception e) {
            String warning = e.getMessage()+"/"+e.getCause()+"/"+e.getClass()+"\n";
            for(int i=0;i<e.getStackTrace().length;i++) {
                warning += e.getStackTrace()[i]+"\n";
            }
            log.warning(warning);
        }
        return str;
    }
}